package com.zwj.hmall.service;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author 张文接
 * @version 1.0
 * @createTime 2024/8/5 21:43
 */
@Service
public class ExecuteService {
    @Resource
    private UserService userService;
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Transactional(propagation = Propagation.REQUIRED)
    public void execute() {
        jdbcTemplate.update("update tb_user set money = money + ? where account = ?", 1000, "jack");
        userService.update();
        int i = 1 / 0;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void execute2() {
        jdbcTemplate.update("update tb_user set money = money + ? where account = ?", 1000, "jack");
        try {
            userService.update2();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //    @Transactional(propagation = Propagation.REQUIRED)
    public void execute3() {
        jdbcTemplate.update("update tb_user set money = money + ? where account = ?", 1000, "jack");
        userService.update3();
    }

    //    @Transactional(propagation = Propagation.REQUIRED)
    public void execute4() {
        userService.update4();
        jdbcTemplate.update("update tb_user set money = money + ? where account = ?", 1000, "jack");
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void execute5() {
        jdbcTemplate.update("update tb_user set money = money + ? where account = ?", 1000, "jack");
        userService.update5();
        int i = 1 / 0;
    }
}
